using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;

namespace Subsync.Core.Subversion
{
	/// <summary>
	/// Author: Juin Min
	/// </summary>
	public class SVNImport : CommandBase
	{
		private java.io.File filepath;
		private SVNURL dest_URL; // destination URL
        private String commit_message;
        private SVNProperties revision_properties;
        private bool use_global_ignores;
        private bool ignoreUnknown; // ignore unknown node types such as device files and pipes
        private SVNDepth depth;

		public SVNImport (java.io.File path, SVNURL dest, String cmtMsg, 
		                 SVNProperties rev_prop, bool gbl_ig, bool unknownig,
		                 SVNDepth dpth)
		{
			Debug.WriteLine ("SVN Import Full blown constructor");
			this.filepath = path;
			this.dest_URL = dest;
			this.commit_message = cmtMsg;
			this.revision_properties = rev_prop;
			this.use_global_ignores = gbl_ig;
			this.ignoreUnknown = unknownig;
			this.depth = dpth;
		}
		
		public SVNImport (string path_to_folder, string final_repo_path)
		{
            this.filepath = new java.io.File(path_to_folder);
            this.dest_URL = SVNURL.parseURIEncoded(final_repo_path);
            this.commit_message = "Import";
            this.revision_properties = null;
            this.use_global_ignores = false; // since general sync tool
            this.ignoreUnknown = true;
            this.depth = SVNDepth.INFINITY;
		}
		
		public SVNImport(java.io.File path, SVNURL dest)
		{
			Debug.WriteLine("SVN Import minimal constructor");
			this.filepath = path;
			this.dest_URL = dest;
			this.commit_message = "Import";
			this.revision_properties = null;
			this.use_global_ignores = false; // since general sync tool
			this.ignoreUnknown = true;
			this.depth = SVNDepth.INFINITY;
		}
		
		public SVNImport(java.io.File path, string dest){
			Debug.WriteLine("SVN Imported requested minimal constructor");
			this.filepath = path;
			this.dest_URL = SVNURL.parseURIEncoded(dest);
			this.commit_message = "Import";
			this.revision_properties = null;
			this.use_global_ignores = false;
			this.ignoreUnknown = true;
			this.depth = SVNDepth.INFINITY;			
		}
		
		public override void Execute()
		{
			Debug.WriteLine("SVN Import Execution");
					
			// Setup library
			Tools.SetupLibrary();
			
			// Setup clients
			SVNClientManager cm = SVNClientManager.newInstance();
			SVNCommitClient cc = cm.getCommitClient();
			
			try 
            {
				cc.doImport(filepath,dest_URL,commit_message,
				            revision_properties,use_global_ignores,
				            ignoreUnknown,depth);
			}
            catch (SVNException exptn)
            {
				throw new SVNExecuteException(exptn.getMessage());
			}
		}
	}
}